home *** CD-ROM | disk | FTP | other *** search
-
- Documentation for the C++ class 'showbox'.
- Written by Chuck Baker
- compuserve user I.D. 70446,441.
- ---------------------------------
-
- Showbox.cpp and showbox.hpp comprise a C++ class for displaying
- DOS-based messages to the screen. That is, showbox is intended to be run
- from DOS applications and it means that showbox does not enter or utilize
- any graphics mode.
-
- Revised June 6, 1993
- The latest revision does not have the problem of the earlier revision
- namely, that it will not crash the heap or anything else regardless of how
- many times the ReDraw function is called. I have tested it extensively and
- I use this class a lot and it leaves the heap balanced once the class has been
- destroyed. During my debugging process I found that I had a tendency
- to allocate too little space for strings that I intended to sprintif into.
- This would blow up the heap so I caution you to 'new' or 'malloc' at least
- twice as much space for changing things like strings as you think you'll need.
- I added the functions 'GetStorage' and 'KillStorage' to help debug the
- problems I was having with crashing the heap.
- Memory for internal strings and screen area preservation is now
- malloc'ed/new'd instead of being of fixed length. This causes the class to
- take even less stack than it did before.
-
- May I recommend that you read all of this. The idea of showing a
- text-based box on the screen I admit, is not too remarkable at first glance
- but this class allows many boxes on the screen and they are easy to
- implement, auto save underlying area, store small on the stack and
- auto destruct/restore underlying area when they destruct.
-
- Showbox writes directly to the screen and assumes video memory
- starts at segment B800h so it cannot be used on monochrome systems where
- video memory starts at segment B000h.
-
- Showbox will display a shaded box with a given title, message
- attributes at optional x-y coords. If no coordinates are supplied then
- the first box will be based at x=10 y=5. Subsequent boxes will be overlapped
- by 3 chars right and 3 chars down. See function 'NextPos'.
- The box is auto-sized up to 60 characters wide,
- then the message will wrap-around to the next line of the box.
- Text is always left justified and the newline character '\n' embedded in the
- message starts a new line. Multiple newline characters create empty lines
- in the box. The underlying area where the box and it's shadow will be
- displayed is saved when the box is created and restored when the box
- is destroyed.
-
- As each box is created with the Box constructor, storage is allocated
- from the heap. One of the Box functions "void Box :: Redraw( char * Msg )"
- allows refilling the box when the same box is used for many messages.
- The box will be resized if the later string is longer than the
- former string.
-
- One of the things that I like about using the heap to store
- the underlying image, message and title is that the Box object can easily
- be put on the stack, that is declared at the beginning of a function just
- like any other type without having to worry about new and delete.
- When the box goes out of scope for any reason it is automatically
- destroyed so you can return from the function without worry about storage.
-
- You may notice some filtering for messages beginning with the letters "SV".
- This is for my application's use and you can remove it without consequence.
-
- The constructor of showbox is overloaded three ways. I use the second
- constructor the most because it gives a consistent look to the program
- due to the autoplacement of the overlapping boxes.
- Remember that the box can be created at the top of a function and re-filled
- later in the function.
- Box :: Box ( char * Title, char * Msg, int ReqXpos, int ReqYpos, uchar ReqAttrib )
- Box :: Box ( char * Title, char * Msg, uchar ReqAttrib )
- Box :: Box ( char * Title, int ReqXpos, int ReqYpos, uchar ReqAttrib )
-
- There is also a sub-class to the Box class named ErrorBox. This is to
- display error messages consistently.
- ErrorBox :: ErrorBox( char * Msg )
- : Box( "ERROR",Msg,BRIGHTWHITEFORGROUND + REDBACKGROUND )
-
- You'll see that this sub-class checks a global variable 'ContinuousFlag'
- to decide whether to wait for a key press after displaying the error message
- or just wait three seconds then continue.
- // flag to tell tests that they should run continuously
- extern unsigned ContinuousFlag;
-
-
- Keep in mind that this is really just a kernal for you to build from.
- I've considered breaking the class up a little more so maybe the most
- base class would do nothing but draw a box. Then have a sub-class to
- overlay the text and one level higher yet to display error messages
- but who has the time?? And, it's useful the way it is.
-
- Check it out, understand it, good luck.
-
- Keep in mind that there may be some bits that left out
- because I removed an include file with some defines in it but
- I think that anything that I left out should be intuitively obvious
- and simple to fix when you compile and link.
-
- Last but not least, if you create a better version of this
- concept I'd enjoy getting hold of it. Thanks.
-
- Chuck
-